package deleted

const (
	maxSequenceNumber = 65535

	seqNumMedian = 1 << 15
	seqNumMax    = 1 << 16

	rtcpIndexSize = 4

	maxRTCPIndex = 0x7FFFFFFF
)

//
//// state for a single RTP SSRC
//type rtpSSRCState struct {
//	ssrc                 uint32
//	index                uint64
//	rolloverHasProcessed bool
//	replayDetector       replaydetector.ReplayDetector
//}
//
//// state for a single RTCP SSRC
//type rtcpSSRCState struct {
//	rtcpIndex      uint32
//	ssrc           uint32
//	replayDetector replaydetector.ReplayDetector
//}
//
//// Context represents a RTP context.
//// Context can only be used for one-way operations.
//// it must either used ONLY for encryption or ONLY for decryption.
//// Note that Context does not provide any concurrency protection:
//// access to a Context from multiple goroutines requires external
//// synchronization.
//type Context struct {
//	rtpSSRCStates  map[uint32]*rtpSSRCState
//	rtcpSSRCStates map[uint32]*rtcpSSRCState
//
//	newSRTCPReplayDetector func() replaydetector.ReplayDetector
//	newSRTPReplayDetector  func() replaydetector.ReplayDetector
//}
//
//// CreateContext creates a new SRTP Context.
////
//// CreateContext receives variable number of ContextOption-s.
//// Passing multiple options which set the same parameter let the last one valid.
//// Following example create SRTP Context with replay protection with window size of 256.
////
////   decCtx, err := srtp.CreateContext(key, salt, profile, srtp.SRTPReplayProtection(256))
////
//func CreateContext(masterKey, masterSalt []byte, opts ...ContextOption) (c *Context, err error) {
//	c = &Context{
//		rtpSSRCStates:  map[uint32]*rtpSSRCState{},
//		rtcpSSRCStates: map[uint32]*rtcpSSRCState{},
//	}
//
//	if err != nil {
//		return nil, err
//	}
//
//	//dstOpts := []ContextOption{ // Default options
//	//	RTPNoReplayProtection(),
//	//	RTCPNoReplayProtection(),
//	//}
//	//dstOpts = append(dstOpts, opts...)
//	// default + opts
//	for _, o := range append(
//		[]ContextOption{ // Default options
//			RTPNoReplayProtection(),
//			RTCPNoReplayProtection(),
//		},
//		opts..., // User specified options
//	) {
//		if errOpt := o(c); errOpt != nil {
//			return nil, errOpt
//		}
//	}
//
//	return c, nil
//}
//
//// https://tools.ietf.org/html/rfc3550#appendix-A.1
//func (s *rtpSSRCState) nextRolloverCount(sequenceNumber uint16) (uint32, func()) {
//	seq := int32(sequenceNumber)
//	localRoc := uint32(s.index >> 16)
//	localSeq := int32(s.index & (seqNumMax - 1))
//
//	guessRoc := localRoc
//	var difference int32 = 0
//
//	if s.rolloverHasProcessed {
//		// When localROC is equal to 0, and entering seq-localSeq > seqNumMedian
//		// judgment, it will cause guessRoc calculation error
//		if s.index > seqNumMedian {
//			if localSeq < seqNumMedian {
//				if seq-localSeq > seqNumMedian {
//					guessRoc = localRoc - 1
//					difference = seq - localSeq - seqNumMax
//				} else {
//					guessRoc = localRoc
//					difference = seq - localSeq
//				}
//			} else {
//				if localSeq-seqNumMedian > seq {
//					guessRoc = localRoc + 1
//					difference = seq - localSeq + seqNumMax
//				} else {
//					guessRoc = localRoc
//					difference = seq - localSeq
//				}
//			}
//		} else {
//			// localRoc is equal to 0
//			difference = seq - localSeq
//		}
//	}
//
//	return guessRoc, func() {
//		if !s.rolloverHasProcessed {
//			s.index |= uint64(sequenceNumber)
//			s.rolloverHasProcessed = true
//			return
//		}
//		if difference > 0 {
//			s.index += uint64(difference)
//		}
//	}
//}
//
//func (c *Context) getRTPSSRCState(ssrc uint32) *rtpSSRCState {
//	s, ok := c.rtpSSRCStates[ssrc]
//	if ok {
//		return s
//	}
//
//	s = &rtpSSRCState{
//		ssrc:           ssrc,
//		replayDetector: c.newSRTPReplayDetector(),
//	}
//	c.rtpSSRCStates[ssrc] = s
//	return s
//}
//
//func (c *Context) getRTCPSSRCState(ssrc uint32) *rtcpSSRCState {
//	s, ok := c.rtcpSSRCStates[ssrc]
//	if ok {
//		return s
//	}
//
//	s = &rtcpSSRCState{
//		ssrc:           ssrc,
//		replayDetector: c.newSRTCPReplayDetector(),
//	}
//	c.rtcpSSRCStates[ssrc] = s
//	return s
//}
//
//// ROC returns SRTP rollover counter value of specified SSRC.
//func (c *Context) ROC(ssrc uint32) (uint32, bool) {
//	s, ok := c.rtpSSRCStates[ssrc]
//	if !ok {
//		return 0, false
//	}
//	return uint32(s.index >> 16), true
//}
//
//// SetROC sets SRTP rollover counter value of specified SSRC.
//func (c *Context) SetROC(ssrc uint32, roc uint32) {
//	s := c.getRTPSSRCState(ssrc)
//	s.index = uint64(roc<<16) | (s.index & (seqNumMax - 1))
//}
//
//// Index returns SRTCP index value of specified SSRC.
//func (c *Context) Index(ssrc uint32) (uint32, bool) {
//	s, ok := c.rtcpSSRCStates[ssrc]
//	if !ok {
//		return 0, false
//	}
//	return s.rtcpIndex, true
//}
//
//// SetIndex sets SRTCP index value of specified SSRC.
//func (c *Context) SetIndex(ssrc uint32, index uint32) {
//	s := c.getRTCPSSRCState(ssrc)
//	s.rtcpIndex = index % (maxRTCPIndex + 1)
//}
